<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="css/index.css">
    <script src="../lib/jquery-3.4.1.js"></script>
    <script src="js/index.js"></script>
</head>

<body>
    <div class="top-box ">
        <ul class="top-nav">
            <li>豆瓣</li>
            <li>读书</li>
            <li>电影</li>
            <li>音乐</li>
            <li>同城</li>
            <li>小组</li>
            <li>阅读</li>
            <li>FM</li>
            <li>事件</li>
            <li>豆品</li>
            <li>更多</li>
        </ul>
        <div class="top-info-box">
            <span>下载豆瓣客户端</span>
            <span>登陆/注册</span>
        </div>
    </div>
    <div class="head-box">
        <div class="head-primary-box">

            <div class="head-primary">
                <div class="head-logo"></div>
                <div class="head-search">
                    <input type="text" placeholder="书名、作者、ISBN" class="search">
                    <input type="submit" class="search-btn">



                </div>
            </div>
        </div>
        <div class="head-nav-box">
            <ul class="head-nav">
                <li>购书单</li>
                <li>电子图书</li>
                <li>豆瓣书店</li>
                <li>2018年度榜单</li>
                <li>2018书影音报告</li>
                <li class="head-nav-shop">购物车</li>
            </ul>
        </div>
    </div>
    <div class="main-box">
        <div class="main-content-box">
            <h2 style="margin-bottom:40px; ">搜索 你的名字</h2>

            <div class="main-books-box">
                <!-- <div class="book-box">
                    <div class="book-img">
                        <img src="" alt="">
                    </div>
                    <div class="book-content">
                        <p class="book-title"></p>
                        <div class="grade-box">
                            <span class="average"></span>
                            <span class="numRaters"></span>
                        </div>
                        <div class="book-content-content">
                            <span class="author"></span>
                            <span class="translator"></span>
                            <span class="publisher"></span>
                            <span class="pubdate"></span>
                            <span class="price"></span>
                        </div>
                    </div>
                </div> -->
            </div>
        </div>
    </div>
    <script>
        var url="https://douban.uieee.com/v2/book/search?q=%E4%BD%A0%E7%9A%84%E5%90%8D%E5%AD%97"
        http(url,getBooks);
        var box=document.getElementsByClassName("main-books-box");
        var books=[];
        function getBooks(res){
            console.log(res);
            for(var i=0;i<15;i++){
                var content=Object();
                content.img=res.books[i].images.large;
                content.title=res.books[i].title;
                content.average=res.books[i].rating.average;
                content.numRaters='('+res.books[i].rating.numRaters+'人评价)';
                content.author=res.books[i].author[0]+'&nbsp;/&nbsp;';
                content.translator=res.books[i].translator[0];
                content.publisher=res.books[i].publisher+'&nbsp;/&nbsp;';
                content.pubdate=res.books[i].pubdate+'&nbsp;/&nbsp;';
                content.price=res.books[i].price;
                 if(typeof(content.translator)=="undefined"){
                     content.translator="";
                 }else{
                     content.translator+='&nbsp;/&nbsp;'
                 }
                books.push(content);
            }
            for(var j=0;j<15;j++){
                var item;
                item=$(`       <div class="book-box">
                    <div class="book-img">
                        <img src="${books[j].img}" alt="">
                    </div>
                    <div class="book-content">
                        <p class="book-title">${books[j].title}</p>
                        <div class="grade-box">
                            <span class="average">${books[j].average}</span>
                            <span class="numRaters">${books[j].numRaters}</span>
                        </div>
                        <div class="book-content-content">
                            <span class="author">${books[j].author}</span>
                            <span class="translator">${books[j].translator}</span>
                            <span class="publisher">${books[j].publisher}</span>
                            <span class="pubdate">${books[j].pubdate}</span>
                            <span class="price">${books[j].price}</span>
                        </div>
                    </div>
                </div>`)
                $(box).append(item)
            }
        }
    </script>
</body>

</html>